package com.example.zkfx

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.CategoryEntity
import com.example.base.entity.GoodsEntity
import com.example.base.entity.Res
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CateVideModel:BaseViewModel() {
    val cateSuccess = MutableLiveData<Res<CategoryEntity>>()
    val cateFail = MutableLiveData<String>()
    fun category(){
        viewModelScope.launch {
            try {
                cateSuccess.postValue(apiServer.category())
            }catch (e:Exception){
                cateFail.postValue(e.message.toString())
            }
        }
    }

    //返回值--分类详情
    val cateXqSuccess = MutableLiveData<Res<GoodsEntity>>()
    val cateXqFail = MutableLiveData<String>()

    fun cateXq(cid:Int, keyword:String, limit:Int,
               news:Boolean, page:Int, priceOrder:String, salesOrder:String){
        viewModelScope.launch {
            try {
                cateXqSuccess.postValue(apiServer.cateXq(cid, keyword, limit, news, page, priceOrder, salesOrder))
            }catch (e:Exception){
                cateXqFail.postValue(e.message.toString())
            }
        }

    }

}